<?php include_once './application/views/sys_admin/common/header.php';  ?>
<!-- admin_main -->
<div class="admin_main">
	<!-- Admin_top end -->
	<?php include_once './application/views/sys_admin/common/user_left.php';  ?>
	<!-- Admin_Left End -->
	<div class="admin_right">
		<div class="admin_right_title">
			<strong>用户管理</strong> >> 会员资料类型管理
		</div>
		<div class="admin_right_con" style="width: 98%;">
			<a class="addtr" href="javascript:;" onclick="addDatum();" >添加资料类型</a>	
			<div class="admin_right_con" style="width: 98%;">
						<table border="0" cellspacing="1" cellpadding="0" bgcolor="#f0f0f0" width="100%">
						  <tbody><tr style="color:#636363;">
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>ID</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>资料名称</strong></td>
							<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>操作</strong></td>
						  </tr>
						 	<?php if($list){foreach ($list as $v){?>
						  	 <tr>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['type_id'];?></td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['name'];?></td>
							<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><a dataname="<?php echo $v['name'];?>" dataid="<?php echo $v['type_id'];?>" href="javascript:;" onclick="changeDatum(this);">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:removeDatum(<?php echo $v['type_id'];?>);">删除</a></td>
						  </tr>	
						  <?php }}?>	
							<tr>
								<td colspan="3"  height="35" align="center" valign="middle" bgcolor="#FFFFFF" class="page"><?php echo $this->pagination->create_links();?></td>
							</tr>
						</tbody>
						
						</table>
					</div>
		</div>
		
	</div>	
<!-- Admin_Right End -->
</div>
<div id="dialog" title="系统提示" style="display:none;">
<div id="msg" style="text-align:center;color:red">&nbsp;</div>
<input type="hidden" name="id" id="id" />
资料名称：<input type="text" name="name" id="name" size="60" /> <br /><br />
<div style="text-align:center;">
<input type="button" style="width: 60px; height:24px" value="关闭" onclick="$('#dialog').dialog('close');"/>
<input type="button" style="width: 60px; height:24px" value="修改" onclick="submitDatum(1);" />
</div>
</div>

<div id="adddialog" title="系统提示" style="display:none;">
<div id="addmsg" style="text-align:center;color:red">&nbsp;</div>
资料名称：<input type="text" name="addname" id="addname" size="60" /> <br /><br />
<div style="text-align:center;">
<input type="button" style="width: 60px; height:24px" value="关闭" onclick="$('#adddialog').dialog('close');"/>
<input type="button" style="width: 60px; height:24px" value="添加" onclick="submitDatum(0);" />
</div>
</div>

<script>
function addDatum(){
	$( "#adddialog" ).dialog({
		height:250,
		width:500,
		modal:true, //蒙层（弹出会影响页面大小）
		title:'添加会员资料类型'
	});
}

function changeDatum(_this){
	var id = $(_this).attr("dataid");
	if(id>0){
		$( "#dialog" ).dialog({
			height:250,
			width:500,
			modal:true, //蒙层（弹出会影响页面大小）
			title:'编辑会员资料类型'
		});
		
		$( "#id").val(id);
		$("#name").val($(_this).attr("dataname"));		
	}
}

function submitDatum(op){
	var id = 0;
	var act = '';
	var name = '';
	if(op > 0){
		act = 'edit';
		name = $("#name").val();
		id = $("#id").val();
	}else{
		act = 'add';
		name = $("#addname").val();
	}

	$.ajax({
		type: "POST",
		url: "/sys_admin/user/user_datum_save",
		data: "act="+act+"&id="+id+"&name="+name,
		success: function(ret){
			if(op > 0){
				$("#dialog" ).dialog();
				$("#msg").html(ret.msg);
				setTimeout(function(){
					$("#dialog" ).dialog("close");
				},3000);
			}else{
				$("#adddialog" ).dialog();
				$("#addmsg").html(ret.msg);
				setTimeout(function(){
					$("#adddialog" ).dialog("close");
				},3000);
			}
			
			
			window.location.reload();
		},
		dataType: "json"
	});	
	
}

function removeDatum(id){
	if(confirm('你确定要删除?'))
	{
		if(id > 0){
			$.ajax({
				type: "POST",
				url: "/sys_admin/user/user_datum_save",
				data: "act=del&id="+id,
				success: function(ret){
					window.location.reload();
				},
				dataType: "json"
			});	
		}	
	}	
}

</script>
<!-- admin_main end -->
</body>
</html>
